<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT">





  <link rel="alternate" href="/atom.xml" title="renhao" type="application/atom+xml">






<meta name="description" content="本文总结下 react hooks 常用实例和场景，并探讨下其中实现原理">
<meta property="og:type" content="article">
<meta property="og:title" content="React hooks">
<meta property="og:url" content="https://huangrenhao.gitee.io/2020/08/28/react-hooks/index.html">
<meta property="og:site_name" content="renhao">
<meta property="og:description" content="本文总结下 react hooks 常用实例和场景，并探讨下其中实现原理">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2020-09-24T06:25:52.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="React hooks">
<meta name="twitter:description" content="本文总结下 react hooks 常用实例和场景，并探讨下其中实现原理">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://huangrenhao.gitee.io/2020/08/28/react-hooks/">





  <title>React hooks | renhao</title>
  








<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">
  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">renhao</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://huangrenhao.gitee.io/2020/08/28/react-hooks/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="renhao">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="renhao">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">React hooks</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-08-28T13:34:31+08:00">
                2020-08-28
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
                  <a href="/categories/React/" itemprop="url" rel="index">
                    <span itemprop="name">React</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2020/08/28/react-hooks/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2020/08/28/react-hooks/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1.8k
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  6
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>本文总结下 react hooks 常用实例和场景，并探讨下其中实现原理<a id="more"></a></p>
<p>hooks 只能在最高层级调用，不能再循环条件或嵌套方法中调用，只能在函数组件中调用，不能再普通函数方法中调用。</p>
<h3 id="useState"><a href="#useState" class="headerlink" title="useState"></a>useState</h3><p>声明状态变量，参数即状态初始值，返回一个数组，数组中为当前的状态值和改变状态值的方法，这个方法接收新状态值。this.setState 是合并状态后返回，useState 直接替换老状态后返回。useState 多次调用之间相互独立，react 根据 useState 出现的顺序来保证 useState 找到对应的 state，故不能写在 if 等条件语句中</p>
<h3 id="useReducer"><a href="#useReducer" class="headerlink" title="useReducer"></a>useReducer</h3><p>接收 reducer、initialState，返回 state 与 dispatch，接收第三个参数 init 函数用于懒初始化（将计算初始 state 的逻辑从 Reducer 抽离出来，即可以和 Redux 直接将 initialState 赋值给 state 相不同）</p>
<h3 id="useEffect"><a href="#useEffect" class="headerlink" title="useEffect"></a>useEffect</h3><ul>
<li>react 首次渲染和之后的每次渲染都会调用以便传给 useEffect 的函数（相当于 componentDidMount、componentDidUpdate）</li>
<li>useEffect 中的函数时异步执行的（不会阻碍浏览器更新视图），componentDidMount 与 componentDidUpdate 中的代码时同步执行的 </li>
</ul>
<p>解绑副作用：传给 useEffect 的副作用函数返回一个新函数，这个新函数会在组件下一次重新渲染的时候执行。</p>
<p>给 useEffect 传递第二个参数来告诉 react 只有当这个参数发生改变时才执行传入的副作用函数（传入空数组即只有首次渲染使用）</p>
<p>闭包陷阱：传入的函数中的变量如果是通过闭包获取的，自然也就是第一次的值。将要依赖的变化的变量放在 useEffect 的第二个参数中。</p>
<blockquote>
<p><a href="https://zhuanlan.zhihu.com/p/84697185" target="_blank" rel="noopener">参考 react useEffect 的陷阱</a></p>
</blockquote>
<h3 id="useRef"><a href="#useRef" class="headerlink" title="useRef"></a>useRef</h3><p>返回一个可变的 ref object，其 current 属性有传入的参数初始化，返回的对象在组件生命周期内一直存在</p>
<h3 id="useMemo、useCallback"><a href="#useMemo、useCallback" class="headerlink" title="useMemo、useCallback"></a>useMemo、useCallback</h3><p><code>useEffect</code>不再区分 <code>mount update</code>两个状态，这意味着函数组件的每一次调用都会执行其内部的所有逻辑，那么会带来较大的性能损耗。</p>
<p>useCallback：<code>useCallback(()=&gt;{ dosomething(a,b)}, [a,b])</code>，a、b为依赖项，返回一个 callback 的记忆版本，只有依赖项改变时才会改变</p>
<p>useMemo：<code>useMemo(()=&gt;computeExpensiveValue(a,b), [a,b])</code></p>
<p><code>useCallback</code>和 <code>useMemo</code>的参数跟 <code>useEffect</code>一致，他们之间最大的区别是 <code>useEffect</code>会用于处理副作用，而前两个hooks不能。</p>
<p><code>useCallback</code>和 <code>useMemo</code>都会在组件第一次渲染的时候执行，之后会在其依赖的变量发生改变时再次执行；并且这两个hooks都返回缓存的值，<code>useMemo</code>返回缓存的 <strong>变量</strong>，<code>useCallback</code>返回缓存的 <strong>函数</strong></p>
<p>React.memo() 是专门给 function component 提供的高阶组件，可以指定一个参数，可以相当于 shouldComponentUpdate 的作用。</p>
<p>局部 pure：React.memo() 在最外层包装了整个组件，局部 pure 就是希望 compunent 的部分不要进行 re-render。</p>
<p>在子组件不需要父组件的值和函数的情况下，只需要使用 <code>memo</code> 函数包裹子组件即可。如果有函数传递给子组件，使用 <code>useCallback</code>。如果有值传递给子组件，使用 <code>useMemo</code>。<code>useEffect</code>、<code>useMemo</code>、<code>useCallback</code> 都是<strong>自带闭包</strong>的。也就是说，每一次组件的渲染，其都会捕获当前组件函数上下文中的状态(<code>state</code>, <code>props</code>)，所以每一次这三种hooks的执行，反映的也都是<strong>当前的状态</strong>，你无法使用它们来捕获上一次的状态。对于这种情况，我们应该使用 <code>ref</code> 来访问。</p>
<h4 id="useMemo："><a href="#useMemo：" class="headerlink" title="useMemo："></a>useMemo：</h4><ul>
<li>返回一个 memoized 值，只有当依赖项变化才会重新计算值，值不变不会重新触发渲染逻辑</li>
<li>useMemo 是在 render 期间执行的，故不能进行一些额外副操作，如网络请求。</li>
<li>没有提供依赖数组则每次都会重新计算 memoized 值</li>
</ul>
<h4 id="useCallback"><a href="#useCallback" class="headerlink" title="useCallback"></a>useCallback</h4><p>返回的是缓存的函数，根据传入的依赖项是否发生变化从而决定是否返回一个新函数</p>
<p>使用场景：</p>
<ul>
<li>如子组件接收父组件的传递的函数作为 props，通常如果父组件更新后子组件也会更新，可以借助 useCallback 返回函数，将这个函数作为 props 传递给子组件</li>
<li>所有依赖本地状态或 props 创建函数、需要用到缓存函数的地方都可以</li>
</ul>
<h3 id="自定义-hook"><a href="#自定义-hook" class="headerlink" title="自定义 hook"></a>自定义 hook</h3><ul>
<li><p>useTimeout：由用户触发，在指定时间之后恢复状态，可以用来节流，比如一段时间内只执行一次函数，避免重复点击触发</p>
<pre class=" language-js"><code class="language-js"><span class="token keyword">import</span> React <span class="token keyword">from</span> <span class="token string">"react"</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> useTimeout <span class="token operator">=</span> <span class="token punctuation">(</span>fn<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token keyword">void</span><span class="token punctuation">,</span> delay<span class="token punctuation">:</span> number <span class="token operator">|</span> <span class="token keyword">null</span> <span class="token operator">|</span> undefined<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">void</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> timerRef <span class="token operator">=</span> React<span class="token punctuation">.</span>useRef<span class="token operator">&lt;</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token keyword">void</span><span class="token operator">></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  timerRef<span class="token punctuation">.</span>current <span class="token operator">=</span> fn<span class="token punctuation">;</span>

  React<span class="token punctuation">.</span><span class="token function">useEffect</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>delay <span class="token operator">===</span> undefined <span class="token operator">||</span> delay <span class="token operator">===</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token keyword">return</span><span class="token punctuation">;</span>

    <span class="token keyword">function</span> <span class="token function">tick</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      timerRef<span class="token punctuation">.</span>current<span class="token operator">?</span><span class="token punctuation">.</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">const</span> timer <span class="token operator">=</span> <span class="token function">setTimeout</span><span class="token punctuation">(</span>tick<span class="token punctuation">,</span> delay<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">clearTimeout</span><span class="token punctuation">(</span>timer<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>delay<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
</ul>
<h2 id="react-实现"><a href="#react-实现" class="headerlink" title="react 实现"></a>react 实现</h2><p>react 中通过类似单链表的形式代替数组来存储数据，通过 next 按照顺序串联起所有的 hook</p>
<p>其他信息，比如 useState 中存储 state 的memorizedState 以及 当前的索引 存储在 Fiber 节点上。 memorizedState 是按照 hook 定义的顺序来放置数据，如果 hook 顺序变化， memorizedState 并不会感知到</p>
<p>所有的 hook 函数都是通过 dispatcher 对象拿到，这个 dispatcher 对象指向同一个 <code>ReactCurrentDispatcher</code></p>
<ul>
<li><p>useState 实现</p>
<p>react 处理渲染带有 hook 组件的核心函数为 <code>renderWithHooks</code>，在这个函数中，在组件挂载时通过 <code>mountWorkInProgressHook</code> 生成一个 hook 对象，传入的初始值被挂载到 memorizedState 上，维护一个队列记录 hook 的改变，返回的改变 state 的函数 dispatch 调用的是 <code>dispatchAction</code> </p>
<p>mountWorkInProgressHook：在这个生成 hook 对象函数中，hook 对象是以链表的形式存储起来，每一个 hook 都有一个指向下一个 hook 的指针 next，并把 hook 对象 <code>firstInProgressHook</code>挂载到 fiber 对象的 memorizedState 上</p>
<p>dispatchAction：记录更新信息，然后交给 react 进行调度处理。react 调度之后会带上 action （dispatch 函数的参数）进入 renderWithHooks，react会使用全局 hook 函数对象上的 useState，这个函数中使用 updateState 计算新 state 值，内部使用 updateReducer ，更新时会沿着链表查找最新的 state 后返回</p>
<p>如果在一个函数中多次调用 dispatch 函数（即 useState 返回的函数），传入的是一个函数计算新的 state，如 <code>handleClick= () =&gt; {dispatch(state +1 ); dispatch(state+2); dispatch(state+3)}</code>，调用 dispatch 实际调用的是 dispatchAction.bind()，这个函数可以拿到对应的 fiber 和 hook 对象的 queue 引用，所以上面的最后结果是在 原始基础上+3。如果传入的是函数，就是那种累加的效果</p>
</li>
<li><p>useEffect 实现</p>
<p>useEffect hook 上的 memorizedState 上存储的是 pushEffect 创建的effect 对象，是一个带环的链表，更新的时候会拿到上一次的 effect，然后对比两次依赖是否相同</p>
</li>
</ul>
<blockquote>
<p>参考</p>
<p><a href="https://github.com/brickspert/blog/issues/26" target="_blank" rel="noopener">github：React hooks 原理</a></p>
<p><a href="https://www.imooc.com/article/302304" target="_blank" rel="noopener">react hook 解析</a></p>
<p><a href="https://github.com/shanggqm/blog/issues/4" target="_blank" rel="noopener">无意识设计-复盘React Hook的创造过程</a></p>
</blockquote>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/08/27/webpack-code-spliting/" rel="next" title="webpack code spliting">
                <i class="fa fa-chevron-left"></i> webpack code spliting
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/08/28/js-bridge/" rel="prev" title="js-bridge">
                js-bridge <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">renhao</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">94</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">19</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#useState"><span class="nav-number">1.</span> <span class="nav-text">useState</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#useReducer"><span class="nav-number">2.</span> <span class="nav-text">useReducer</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#useEffect"><span class="nav-number">3.</span> <span class="nav-text">useEffect</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#useRef"><span class="nav-number">4.</span> <span class="nav-text">useRef</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#useMemo、useCallback"><span class="nav-number">5.</span> <span class="nav-text">useMemo、useCallback</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#useMemo："><span class="nav-number">5.1.</span> <span class="nav-text">useMemo：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#useCallback"><span class="nav-number">5.2.</span> <span class="nav-text">useCallback</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#自定义-hook"><span class="nav-number">6.</span> <span class="nav-text">自定义 hook</span></a></li></ol><li class="nav-item nav-level-2"><a class="nav-link" href="#react-实现"><span class="nav-number"></span> <span class="nav-text">react 实现</span></a></li></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">renhao</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">265.9k</span>
  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  










  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: false,
        appId: '2P1xqUWiCoNm14MH4yhURlJi-gzGzoHsz',
        appKey: 'uJN0uagHIVgXtBO1OuLV9Ban',
        placeholder: 'Just go go',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  





  

  

  

  
  

  

  

  

</body>
</html>
